package com.weyoung.app.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weyoung.app.mapper.NetworkStatsMapper;
import com.weyoung.app.service.NetworkStatsService;
import com.weyoung.entity.NetworkStats;
import org.springframework.stereotype.Service;

@Service
public class NetworkStatsServiceImpl extends ServiceImpl<NetworkStatsMapper, NetworkStats> implements NetworkStatsService {
    
    @Override
    public void saveOrUpdateStats(NetworkStats stats) {
        LambdaQueryWrapper<NetworkStats> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(NetworkStats::getUrl, stats.getUrl())
                .eq(NetworkStats::getUserId, stats.getUserId())
                .eq(NetworkStats::getDate, stats.getDate())
                .eq(NetworkStats::getNetwork, stats.getNetwork());
        
        NetworkStats existing = this.getOne(wrapper);
        if (existing == null) {
            this.save(stats);
        }
    }
} 